<template>
    <div>
        <a-row>
            <a-radio-group name="radioGroup" :default-value="radioVal">
                <a-radio
                    :value="value"
                    @click="radioClick"
                    v-for="({ value, label }, k) in radioList"
                    :key="k"
                    :checked="radioVal == value"
                >
                    {{ label }}
                </a-radio>
            </a-radio-group>
        </a-row>
        <a-row type="flex" justify="space-between" align="middle" style="margin-top: 15px">
            <a-col>
                <a-checkbox @change="onChange" :checked="checked">
                    不在询问
                </a-checkbox>
            </a-col>
        </a-row>
    </div>
</template>
<script>
    import { writeData } from '@/util/file-action'
    export default {
        name: 'CloseDialog',
        data() {
            return {
                checked: false,
                radioList: [
                    { label: '退出软件', value: 'exit' },
                    { label: '最小化到托盘', value: 'tray' },
                ],
                radioVal: 'exit',
                action: '',
            }
        },
        watch: {
            '$store.state.videos.dontAsk': {
                handler(nval) {
                    this.radioVal = nval.opt
                    this.checked = nval.value
                },
                deep: true,
                immediate: true,
            },
        },
        destroyed() {
            this.radioVal = 'exit'
        },
        methods: {
            onChange(e) {
                this.checked = e.target.checked
                const data = { value: this.checked, opt: this.radioVal }
                if (writeData(data, 'dontAsk', 'video', true)) {
                    this.$store.commit('videos/setDontAsk', data)
                }
            },
            radioClick() {
                this.radioVal = this.radioVal == 'exit' ? 'tray' : 'exit'
            },
            setVisible(action = '') {
                this.action = action
                this.checked = false
            },
        },
    }
</script>
<style lang="less" scoped></style>
